package com.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

import com.spring.controller.web.ContentController;

public class Validation {
	
	private static final Logger logger = Logger.getLogger(ContentController.class);
    
	
	private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	private static  Pattern pattern;
	private static  Matcher matcher; 
	
	public static final boolean emailValidator( String hex ){	  
			  pattern = Pattern.compile(EMAIL_PATTERN);
			  matcher = pattern.matcher(hex);
			  return matcher.matches();
	 
	}
	
	public static final Date getDate(String dateToParse, boolean defaultNow){
		SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
	     Date myDate = null;
	     logger.debug("FORMATTING STRING:"+dateToParse+" USING FORMAT :"+"dd/MM/yyyy");
		try {
			myDate = df.parse(dateToParse);
		} catch (ParseException e) {
			if (defaultNow)	myDate =new Date();
			logger.error("ERROR PARSING DATE: RETURNING NULL DATE:"+e.getMessage());
		}
		return myDate;
	}
}
